<?php

namespace App\Service\Moment\v1_1_4;

use App\Constants\ErrorCode;
use App\Model\Moment;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 真人头像认证发动态
 */
class ShareAvatarMomentService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $userProfile = UserProfile::getProfile($userId, false);
        if (!UserProfile::checkAvatarVrfied($userId, $userProfile)) {
            return $this->setError(ErrorCode::REAL_AVATAR_NOT_VRFY, '还未通过真人头像认证～');
        }
        if (Moment::checkRealAvatar($userId, 1800)) {
            return $this->setError(ErrorCode::REAL_AVATAR_LMT, '你半小时内已经分享过真人头像动态～');
        }
        $ret = Moment::create([
            'user_id' => $userId,
            'user_gender' => $userProfile->gender,
            'words' => '已通过官方真人认证，头像为本人，真诚交友。',
            'images' => [$userProfile->avatar],
            'status' => Moment::STATUS_OK,
            'moment_type' => Moment::TYPE_REAL_AVATAR_SHARE
        ]);

        //动态事件
        // make(EventDispatcherInterface::class)->dispatch(new PubMomentEvent($userId, $ret['id']));
        return ['result' => 1];
    }
}
